function day2db(data,year,longitude,latitude,layer,time,kind,element)
   implicit none
   integer :: longitude
   integer :: latitude
   integer :: layer
   integer :: time
   integer ::year
   integer :: day2db
   integer :: m2,k2
   character(len=32) :: kind
   character(len=32) :: element
   integer :: month
   integer :: day
   integer :: iret
   !real, pointer :: data(:,:,:,:)
  ! allocate(data(longitude,latitude,layer,time))
   !print *,data
   real,dimension(longitude,latitude,layer,time) :: data
   do m2=1,time
	   do k2=1,layer
         !print *,"begin to write the element db"
		 call day2date(year,m2,month,day,iret)
		! print *,month
		 !print *,day
		 
	     call eleg_write(kind,element,k2,year,month,day,0,longitude,latitude,data(:,:,k2,m2),iret)
		  if(iret /= 0) then
		     print *,"iret is"
			 print *,iret
		  endif  
	   enddo 
   enddo
   !deallocate(data)
   
   day2db =0;
   return
end